<template>
  <div class="publicBox" id="equipmentCSS">
          <div class="boxItem " id="publicSearch">

<el-form ref="form" :inline="true"  class="demo-form-inline">
    <el-row>
        <el-form-item label="品牌">
            <el-input class="pubIpt" v-model="ruleForm.brand"  placeholder="请输入设备品牌"></el-input>
        </el-form-item>
        <el-form-item label="型号">
            <el-input class="pubIpt" v-model="ruleForm.model"  placeholder="请输入设备型号"></el-input>
        </el-form-item>
        <el-form-item label="SN">
            <el-input class="pubIpt" v-model="ruleForm.sn"  placeholder="请输入设备SN号"></el-input>
        </el-form-item>
        <el-form-item label="所在仓库">
            <el-select v-model="ruleForm.warehouseType" filterable  placeholder="全部" class="pubSlt97">
                <el-option
                v-for="item in $warehouse()"
                :key="item.id"
                :label="item.name"
                :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>
      <el-form-item>
          <el-button class="pubBtnBlue" type="primary" @click="init">查询</el-button>
      </el-form-item>
    </el-row>

    <el-row  class="two_form publicBox">
    <el-row class="two_form_item">
        <el-form-item>
            <el-button class="pubBtnGree" @click="addstock" type="primary">设备入库</el-button>
    </el-form-item>
    <el-form-item>
                  <publicUpdate 
                  @successFn="successUpload" 
                  :hrefUpload="action"
                  textUpload="批量入库"
                  ></publicUpdate>
    </el-form-item>
    <el-form-item label="">
        下载批量新增模板|<a href="#" @click="downXlsx" style="color:#617ADA">模块批量新增.xlsx</a>|
    </el-form-item>
    </el-row>
    <el-row  class="two_form_item_a">
        <el-form-item>
            <el-button class="pubBtnBlueL pubBtnBlueL_a" @click="exportFn" type="primary">导出</el-button>
        </el-form-item>
    </el-row>
    
</el-row>
</el-form>
          </div>
          <public-table class="colum" 
          @changePage="changePage" 
          :btn=[] 
          :columnDefs="columnDefs" 
          :tableData="tableData" 
          :order=true
          ></public-table>
  </div>
</template>

<script>
import publicTable from "@/components/public/publicTable.vue"
import publicUpdate from "@/components/public/publicUpdate.vue"
import * as API from "@api/equipmenter.js"
import * as pubAPI from '@api/public.js'
import  baseConfig from '@api/common/baseconfig.js'
export default {
  components: {
         publicTable,
         publicUpdate
  },
  data() {
    return {
        columnDefs :[
            {headerName: '设备ID', field: 'no',width:110},
            {headerName: '品牌', field: 'brandname',width:90},
            {headerName: '型号', field: 'model',width:100},
            {headerName: '设备类型', field: 'typename',width:100},
            {headerName: '设备名称', field: 'name',width:105},
            {headerName: 'SN', field: 'sn',width:210},
            {headerName: '供应商', field: 'suppliername',width:270},
            {headerName: '所在仓库', field: 'warehousetypename',width:90},
            {headerName: '入库时间', field: 'createtime',width:150}
        ],
        tableData: [],
        download:baseConfig.baseUrl+"/v1/flash/equipments/template/download",
        action:baseConfig.baseUrl+"/v1/flash/module/template/import",
        ruleForm:{
           page:1,
           size:100,
           isbinding:0,   //  0  就是库存管理的  1  就是绑定了终端
           model:"",
           brand:"",
           sn:"",
           warehouseType:null
        },
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {


  },
  // 监控data中的数据变化
  watch: {


 },
  methods: {
    successUpload(res){          //文件上传成功回调
        if(res.IsPositive){
                  this.$message.success({message:"文件上传成功"})
                  this.init()
                }else{
                  this.$message.error({message:res.ErrorCode})
                }
    },
    downXlsx(){
          window.location.href =this.download
    },
    changePage(pageSize,pageNum){
        this.ruleForm.size=pageSize;this.ruleForm.page=pageNum
        this.init()
     },
    async exportFn(){
       await API.exportTerminal(this.ruleForm).then(res=>{
         pubAPI.creatExcelFn("终端设备管理.xlsx",res)
       })
    },
    async init(){
           await API.getTerminal(this.ruleForm).then(res=>{
                this.tableData=res.Data
                // console.log("res",res.Data)
           })
    },
    addstock(){
      this.$router.push({path:'/platform/equipment/stockAdd'})
    }
  },
  created() {
     this.init()
  },
  mounted() {


  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='less' scoped>
@import "../../styles/less/public.less";
  #equipmentCSS{
    .boxItem{
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      .demo-form-inline{
        align-items: center;
      }
      .itemp{
      font-size: 16px;
      } 
    } 
    .two_form{
        display: block;
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        .two_form_item{
            width: 1190px;
        }
        .two_form_item_a{
            width: 90px;
        }
    }
  }
</style>